import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:my_app/app/config/app_config.dart';
import 'package:my_app/app/config/smart_dialog_config.dart';
import 'package:my_app/app/data/services/api_service.dart';
import 'package:my_app/app/data/services/shared_preferences_service.dart';
import 'package:my_app/app/core/theme/app_theme.dart';
import 'package:my_app/app/modules/home/home_page.dart';
import 'package:my_app/app/routes/pages.dart';

Future<void> main() async {
  await initServices(); // 等待服务初始化.
  runApp(GetMaterialApp(
    title: AppConfig.appName,
    debugShowCheckedModeBanner: true,
    // initialRoute: Routes.SPLASH,
    theme: appThemeData,
    defaultTransition: Transition.fade,
    // initialBinding: SplashBinding(),
    getPages: AppPages.pages,
    // builder: (context, child) {
    //   ScreenUtil.init(context);
    //   return MyApp();
    // },
    // smart dialog 引入
    navigatorObservers: [FlutterSmartDialog.observer],
    // smart dialog 引入
    builder: FlutterSmartDialog.init(
      builder: (context, child) => GestureDetector(
        onTap: () {
          // 点击空白区域时取消聚焦
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: child,
      ),
      // toastBuilder: (msg) => CustomToastWidget(msg: msg),
    ),
    home: HomePage(),
  ));
}

Future<void> initServices() async {
  print('starting services ...');
  Get.put(SharedPreferencesService());
  Get.put(ApiService());
  SmartDialogConfig.defaultConfig();
  print('All services started...');
}
